﻿using LdtDataEngin.ModuleDetail.PersonnelAnalysis.PersonnelModel.Interface;
using LdtJudge.DataEngine.Common.CommHelp;
using LdtJudge.DataEngine.Model.Personnel;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace LdtDataEngin.ModuleDetail.PersonnelAnalysis.PersonnelModel.Determine
{
    public class A2Determine : IDetermine
    {
        public int sp_sid { get; set; }
        public int prosecutor_count { get; set; }

        /// <summary>
        /// 二审刑事当事人处理
        /// </summary>
        /// <param name="Pre"></param>
        /// <param name="Name"></param>
        /// <param name="spIndex"></param>
        /// <param name="mcs"></param>
        /// <returns></returns>
        public bool IsMatchAccusedOrProsecutor(string Pre, string Name, string spIndex, ElementSpokeName mcs)
        {
            if (string.IsNullOrEmpty(Name))
            {
                return false;
            }
            string name = "";
            if (Pre == "被上诉")
            {
                name = "被";
            }
            spIndex = (sp_sid - prosecutor_count).ToString();
            string FirstName = Name == "" ? "" : Name.Substring(0, 1);
            ChnNumFormat chnum = new ChnNumFormat(); string[] AllMatchStr = new string[] { Pre, spIndex + Pre, Pre + spIndex + "(?=$)", chnum.NumToChn(spIndex) + Pre, Pre + chnum.NumToChn(spIndex) + "(?=$)", Pre + "告" + chnum.NumToChn(spIndex) + "(?=$)", Pre + "告" + spIndex + "(?=$)", Pre + FirstName, Pre + "上(?=$)", "^" + Name, "第" + chnum.NumToChn(spIndex) + Pre + "上" };
            string RegStr = string.Join("|", AllMatchStr);

            if (name != "")
            {
                RegStr += "|" + name;
            }
            if (string.IsNullOrEmpty(mcs.ES_FullName))
            {
                MatchCollection matches = new Regex(RegStr).Matches(mcs.ES_ShortName);
                if (matches.Count < 2)
                {
                    return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                }
                else
                {
                    if (string.IsNullOrEmpty(mcs.ES_FullName) && mcs.ES_RoleIndex == spIndex)
                    {
                        return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 二审刑事代理人处理
        /// </summary>
        /// <param name="Pre"></param>
        /// <param name="Mid"></param>
        /// <param name="Name"></param>
        /// <param name="spIndex"></param>
        /// <param name="mcs"></param>
        /// <param name="ProxyName"></param>
        /// <returns></returns>
        public bool IsMatchProxy(string Pre, string Mid, string Name, string spIndex, ElementSpokeName mcs, string ProxyName = "")
        {
            if (string.IsNullOrEmpty(Name))
            {
                return false;
            }

            string ProxyFirstName = Name.Substring(0, 1);
            string FirstName = Name.Substring(0, 1);
            string ending = "代";
            ChnNumFormat chnum = new ChnNumFormat();
            List<string> AllMatchStr = new List<string> { spIndex + Pre + ending, Pre + spIndex + ending, chnum.NumToChn(spIndex) + Pre + ending, Pre + chnum.NumToChn(spIndex) + ending, Pre + FirstName + ending, Pre + Mid + ending + "(?=$)", Pre + Mid + ending + ProxyFirstName + "(?=$)", Pre + ending, "^" + Name, "^" + ProxyFirstName + "(?=$)", Pre + ending + ProxyFirstName };
            if (!string.IsNullOrEmpty(ProxyName))
            {
                AllMatchStr.Add(ProxyName);
            }
            if (spIndex == "1")
            {
                AllMatchStr.Add("辩");
            }
            string RegStr = string.Join("|", AllMatchStr);
            if (string.IsNullOrEmpty(mcs.ES_FullName))
            {
                MatchCollection matches = new Regex(RegStr).Matches(mcs.ES_ShortName);
                if (matches.Count < 2)
                {
                    return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                }
                else
                {
                    if (string.IsNullOrEmpty(mcs.ES_FullName) && mcs.ES_RoleIndex == spIndex)
                    {
                        return new Regex(RegStr).IsMatch(mcs.ES_ShortName);
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }
    }
}
